package com.u.social.sale.service.impl;

import com.u.social.sale.entity.Cart;
import com.u.social.sale.mapper.CartMapper;
import com.u.social.sale.model.CartDTO;
import com.u.social.sale.service.ICartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Alex Wu
 * @since 2025-03-10
 */
@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements ICartService {

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean saveCart(CartDTO cart) {
        Cart cartEntity = new Cart();
        cartEntity.setUserId(cart.getUserId());
        cartEntity.setProductId(cart.getProductId());
        cartEntity.setSkuId(cart.getSkuId());
        cartEntity.setPrice(cart.getPrice());
        cartEntity.setProductNum(cart.getProductNum());
        cartEntity.setIsChoice(cart.getIsChoice());
        return save(cartEntity);
    }
}
